package edu.spec.wechat.service.impl;

import edu.spec.wechat.dao.iface.IWechatMenuDao;
import edu.spec.wechat.model.WechatMenu;
import edu.spec.wechat.model.WechatMenuDto;
import edu.spec.wechat.service.iface.IWechatMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by MadFrog on 2016/10/28.
 */
@Service("wechatMenuService")
public class WechatMenuService implements IWechatMenuService {

    @Autowired
    private IWechatMenuDao wechatMenuDao;

    @Override
    public void add(WechatMenu menu) {
        wechatMenuDao.add(menu);
    }

    @Override
    public void delete(int id) {
        //TODO 检查是否有子菜单
        wechatMenuDao.delete(id);
    }

    @Override
    public void update(WechatMenu menu) {
        wechatMenuDao.update(menu);
    }

    @Override
    public WechatMenu load(int id) {
        return wechatMenuDao.load(id);
    }

    @Override
    public List<WechatMenu> listAll() {
        return wechatMenuDao.listAll();
    }

    @Override
    public WechatMenu loadByKey(String key) {
        return wechatMenuDao.loadByKey(key);
    }

    @Override
    public List<WechatMenuDto> generateWechatMenuDto() {
        List<WechatMenu> menus = this.listAll();
        List<WechatMenuDto> menuDtos = new ArrayList<WechatMenuDto>();
        WechatMenuDto dto = null;
        for (WechatMenu m : menus){
            //一级菜单
//            if(m.getPid()==null || m.getPid()==0){
//                dto = new WechatMenuDto();
//                dto.setName(m.getName());
//                dto.setType(m.getType());
//                dto.setUrl(m.getUrl());
//                dto.setKey(m.getKey());
//
//            }
            //二级菜单
        }
        return null;
    }
}
